package cn.kmbeast.service.impl;

import cn.kmbeast.pojo.api.ApiResult;
import cn.kmbeast.pojo.api.Result;
import cn.kmbeast.pojo.dto.query.extend.HealthModelConfigQueryDto;
import cn.kmbeast.pojo.dto.update.HealthModelConfigDto;
import cn.kmbeast.pojo.entity.HealthModelConfig;
import cn.kmbeast.service.HealthModelConfigService;
import cn.kmbeast.mapper.HealthModelConfigMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class HealthModelConfigServiceImpl implements HealthModelConfigService {

    @Resource
    private HealthModelConfigMapper healthModelConfigMapper;


    @Override
    public Result<Void> save(HealthModelConfig healthModelConfig) {
        int insert = healthModelConfigMapper.insert(healthModelConfig);
        return  insert  != 0 ? ApiResult.success() : ApiResult.error("添加失败");
    }

    @Override
    public Result<Void> batchDelete(List<Long> ids) {
        int i = healthModelConfigMapper.batchDelete(ids);
        return  i  != 0 ? ApiResult.success() : ApiResult.error("删除失败");
    }

    @Override
    public Result<Void> update(HealthModelConfig healthModelConfig) {
        int i = healthModelConfigMapper.updateByPrimaryKey(healthModelConfig);
        return  i  != 0 ? ApiResult.success() : ApiResult.error("修改失败");
    }

    @Override
    public Result<List<HealthModelConfig>> query(HealthModelConfigQueryDto healthModelConfigQueryDto) {
        List<HealthModelConfig> queryData = healthModelConfigMapper.query(healthModelConfigQueryDto);
        //按条件查询  返回查询的总数
        Integer totalCount = healthModelConfigMapper.queryCount(healthModelConfigQueryDto);
        return ApiResult.success(queryData,totalCount);
    }
}
